<template>
<div class="page-container-padding">
  <div>
    <span><el-date-picker style="width:160px;" v-model="queryDate" size="mini" :clearable="false"></el-date-picker></span>
    <span style="margin-left:6px;"><el-button type="primary" size="mini" @click="toQueryStatistics">查询</el-button></span>
  </div>
  <div style="margin:6px 0;">权益合计表</div>
  <div>
    <el-table border stripe show-summary :data="statisticsList">
      <el-table-column prop="admin_name" label="姓名" width="110px"></el-table-column>
      <el-table-column prop="rights" label="客户权益" width="130px"></el-table-column>
    </el-table>
  </div>

  <div style="margin:6px 0;">详情表</div>
  <div>
    <el-table border stripe show-summary :summary-method="tableSumMethod" :data="detailList">
      <el-table-column prop="create_date" label="日期" width="110px"></el-table-column>
      <el-table-column prop="investor_code" label="资金号" width="110px"></el-table-column>
      <el-table-column prop="investor_name" label="名称" width="130px" show-overflow-tooltip></el-table-column>
      <el-table-column prop="rights" label="权益" width="130px"></el-table-column>
    </el-table>
  </div>
</div>
</template>

<script>
import { datetimeToStr } from '@/utils/datetimeUtils'
import { getRightsStatistics } from '@/api/departmentWork/customer'
export default{
  data(){
    return {
      queryDate: new Date(),
      statisticsList: [],
      detailList:[]
    }
  },
  mounted() {
    this.toQueryStatistics()
  },
  methods:{
    tableSumMethod(param){
      const { columns, data } = param;
      const sums = [];
      const sumColumnIndexes = [3]
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => Number.isNaN(value)) && sumColumnIndexes.indexOf(index)>-1) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!Number.isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index] = sums[index].toFixed(2);
        } else {
          sums[index] = '';
        }
      });
      return sums;
    },

    toQueryStatistics(){
      const paraData = {
        date: datetimeToStr(this.queryDate, true, '')
      }
      getRightsStatistics(paraData).then(res => {
        const data = res.data
        this.statisticsList = data.statistics_data
        this.detailList = data.detail_data
      })
    }
  }
}
</script>

<style>
</style>
